clear all
set more off

* set directory where code and data is stored
global main_dir // insert directory here

cd "$main_dir/data"
do "$main_dir/migration_processing_macros"


********************************************************************************

/* 1. the first step is to find the RCA buildings in the Infutor data.  this is 
important because we need to separate migrants to the new buildings from 
migrants to the immediate area, and it takes a lot of work because
buildings can have multiple addresses */

********************************************************************************

* first, we put the RCA addresses into the format used in infutor
infutorize_addresses

* second, we use a variety of string matching techniques to merge the datasets
find_matches

********************************************************************************

/**** 2. with those matches in place, we pull moves that are close to a new 
building from the infutor data */


********************************************************************************

* first, put together subset of infutor addresses for our MSAs to reduce file size
subset_addresses

* second, pull all individuals that have lived close to a new building
pull_moves

* third, reshape the file to unique address-building pairs and identify people
* in new buildings
long_file


********************************************************************************

/**** 3. using this set of move/building pairs, we can construct a variety of 
samples for the different analyses in the paper */

********************************************************************************

* first, make the files for the near-far
near_far_file

* second, make the files for the near-near
near_near_file

* third, make the files for the ddd
ddd_file

* fourth, far-far robustness check
far_far

* fifth, no pioneer robustness check
no_pioneer

* sixth, make file that's better for general summary statistics
near_far_quantity_file

* finally, make a collapsed file for some additional summary statistics
collapse_to_summary

